window.onload = function(){
    var height = $(window).height();
    var height2 = $('.excellent').height();
    $('.view-box').height(height - height2 - 100);
    $('.view-box').height(height  - 100);
    var myScroll = new IScroll('#wrapper', {
        mouseWheel: true,
        scrollbars:false
    });
    var myScroll2 = new IScroll('#wrapper2', {
        mouseWheel: true,
        scrollbars:false
    });
};

$(function(){

    $('.dianzhan').on('tap',function(){
        // console.log('hdha');
        // return;
        obj = $(this);
        var id = ($(this).attr('data'));
        if(id=="In"){
            mui.alert("暂不支持为自己点赞");
        }else{
            var btnArray = ['否', '是'];
            mui.confirm('确定点赞么？', btnArray, function(e) {
                if (e.index == 1) {
                    $.get("/index/rankings/fabulous",{id:id},function(data){
                        console.log(data);
                        if(data.code==200){
                            obj.prop("class","dianzhan checked");
                            str = '/static/images/dianzhan2-active.png';
                            //console.log(str);
                            obj.prop("src",str);

                        }else{
                            layer.open({
                                content: data.msg
                                ,skin: 'msg'
                                ,time: 2 //2秒后自动关闭
                            });
                        }
                    });
                }
            })
        }

    });
    $('.leavMsg').on('tap',function(){
        var bumen_id = $(".leavMsg").attr("data");
        // console.log(bumen_id);
        //数据请求的接口
        if($(".mui-active").attr("href")=='#item1'){
            var url = "/index/Rankings/msg";
        }else if($(".mui-active").attr("href")=="#item2"){
            var url = "/index/Rankings/msg?bumen="+bumen_id+"";
        }
        var index = layer.open({
            shadeClose:false
            ,type: 1
            ,content: '<div class="msgBox">'+
            '<span class="del" style="float:right;display:inline;color:red;font-size:16px;margin:15px 15px 0px 0px;">X</span>'+
            '<iframe src="'+url+'" width="100%" style="border:none;height:4.2rem"></iframe>'+
            '</div>'
            ,anim: 'up'
            ,style: 'position:fixed;transition: all 2s; bottom:0; left:0; width: 100%;height:4.2rem; border-radius: 10px 10px 0 0; border:none;overflow: hidden;'
        });
        $('.del').on('tap',function(){
            layer.close(index);
        })
    });

    function downRefresh() {
        var str = '<li>'+
            '<div class="modular">'+
            '<a href="javascript:;">'+
            '<div class="modular-cont">'+
            '<h3><span class="mui-icon iconfont">&#xe63f;</span>关于端午节遇上京东6.18怎么办？</span></span></h3>'+
            '<p>当然是有多少钱，就买多少钱呗，么钱咋办啊盛大盛大盛大</p>'+
            '<time>5月20日<span class="mui-pull-right mui-icon mui-icon-arrowright"></span></time>'+
            '</div>'+
            '</a>'+
            '</div>'+
            '</li>';
        //业务逻辑代码，比如通过ajax从服务器获取新数据；
        setTimeout(function(){
            if(downNum == 3){
                layer.open({
                    content: '已经是最新的消息~'
                    ,skin: 'msg'
                    ,time: 2 //2秒后自动关闭
                });
            }else{
                $('#container').find('li').eq(0).before(str);
                downNum++;
            }
            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
        },1000)
        //注意，加载完新数据后，必须执行如下代码，注意：若为ajax请求，则需将如下代码放置在处理完ajax响应数据之后
        //没有更多内容了，endPulldown 传入true， 不再执行下拉刷新

    }
    function upLoad(){
        var str = '<li>'+
            '<div class="modular">'+
            '<a href="javascript:;">'+
            '<div class="modular-cont">'+
            '<h3><span class="mui-icon iconfont">&#xe63f;</span>关于端午节遇上京东6.18怎么办？</span></span></h3>'+
            '<p>当然是有多少钱，就买多少钱呗，么钱咋办啊盛大盛大盛大</p>'+
            '<time>5月20日<span class="mui-pull-right mui-icon mui-icon-arrowright"></span></time>'+
            '</div>'+
            '</a>'+
            '</div>'+
            '</li>';
        var _this = this;
        setTimeout(function(){
            if(downNum == 3){
                _this.endPullupToRefresh(true);
            }else{
                $('#container').append(str);
                _this.endPullupToRefresh(false);
                downNum++;
            }
        },1000)
        //注意，加载完新数据后，必须执行如下代码，注意：若为ajax请求，则需将如下代码放置在处理完ajax响应数据之后
        //没有更多内容了，endPulldown 传入true， 不再执行下拉刷新
    }



});

$('.xiala').on('tap',function(event){
    $.post("/index/Rankings/departmenList",{},function(data){
        if(data.code==200){
            var str = '<div class="depList">';
            $.each(data.departmen,function(i,v){
                str+= '<button  class="mui-btn depBtn mui-pull-left" data="'+v.id+'">'+v.departmen_name+'</button>';
            });
            str+='</div>';
            setTimeout(function(){
                var index2 = layer.open({
                    title: [
                        '选择部门',
                        'background-color: #4990E2; color:#fff;'
                    ]
                    ,content: str
                });
                $('.depBtn').on('tap',function(){
                    id = $(this).attr("data");
                    $(".leavMsg").attr("data",id);

                    $.get("/index/Rankings/otherdepartment",{id:id},function(data){
                        console.log(data);
                        layer.close(index2);
                        var $str = '<div class="excellent">';
                        var $img = '';
                        var ii='';
                        var In = "In";
                        var $Myimg = '<img class="dianzhan" onclick="dianzhan2()" src="/static/images/dianzhan2.png"/>';
                        $("#scroller2").empty();
                        $.each(data.data,function (i,v) {
                            var ii = i+1;
                            var img = 0;
							if(v.zan==1){
								$img = '<img class="dianzhan1 checked" src="/static/images/dianzhan2-active.png"/>';
							}else{
								$img = '<img class="dianzhan1" data="'+v.id+'"  src="/static/images/dianzhan2.png"/>';
							}

                            if(i==0){
                                $str +='<div class="excellent-first">'+
                                    '<div class="excellent-left mui-pull-left">'+
                                    ""+$img+""+
                                    '<span>'+v.departmen_name+"-"+v.nickname+'</span>'+
                                    '</div>'+
                                    '<div class="excellent-right mui-pull-right">'+
                                    '<div class="mui-pull-left jifen">'+
                                    '<img src="/static/images/jifen.png"/>'+
                                    '<p>'+v.integral+'分</p>'+
                                    '</div>'+
                                    '<div class="mui-pull-left imgBox">'+
                                    '<img src="/static/images/diyi.png"/>'+
                                    '</div>'+
                                    '</div>'+
                                    '</div>';
                            }else if(i==1){

                                $str += '<div class="excellent-second">'+
                                    '<div class="excellent-left mui-pull-left">'+
                                    ""+$img+""+
                                    '<span>'+v.departmen_name+"-"+v.nickname+'</span>'+
                                    '</div>'+
                                    '<div class="excellent-right mui-pull-right">'+
                                    '<div class="mui-pull-left jifen">'+
                                    '<img src="/static/images/jifen.png"/>'+
                                    '<p>'+v.integral+'分</p>'+
                                    '</div>'+
                                    '<div class="mui-pull-left imgBox">'+
                                    '<img src="/static/images/dier.png"/>'+
                                    '</div>'+
                                    '</div>'+
                                    '</div>';
                            }else if(i==2){
                                $str+='<div class="excellent-third">'+
                                    '<div class="excellent-left mui-pull-left">'+
                                    ""+$img+""+
                                    '<span>'+v.departmen_name+"-"+v.nickname+'</span>'+
                                    '</div>'+
                                    '<div class="excellent-right mui-pull-right">'+
                                    '<div class="mui-pull-left jifen">'+
                                    '<img src="/static/images/jifen.png"/>'+
                                    '<p>'+v.integral+'分</p>'+
                                    '</div>'+
                                    '<div class="mui-pull-left imgBox">'+
                                    '<img src="/static/images/disan.png"/>'+
                                    '</div>'+
                                    '</div>'+
                                    '</div>'+
                                    '</div><ul class="mui-table-view ">';
                            }else{
                                $str +='<li class="mui-table-view-cell excellent">'+
                                    '<div class="excellent-left mui-pull-left">'+
                                    ""+$img+""+
                                    '<span>'+v.departmen_name+"-"+v.nickname+'</span>'+
                                    '</div>'+
                                    '<div class="excellent-right mui-pull-right">'+
                                    '<div class="mui-pull-left jifen">'+
                                    '<img src="/static/images/jifen2.png"/>'+
                                    '<p>'+v.integral+'分</p>'+
                                    '</div>'+
                                    '<div class="mui-pull-left imgBox">'+
                                    '<span>'+ii+'</span>'+
                                    '</div>'+
                                    '</div>'+
                                    '</li>';
                            }
                        });
                        $.each(data.one,function(k,v){
                            $str +='<li class="mui-table-view-cell excellent">'+
                                '<div class="excellent-left mui-pull-left">'+
                                ""+$Myimg+""+
                                '<span>'+v.departmen_name+"-"+v.nickname+'</span>'+
                                '</div>'+
                                '<div class="excellent-right mui-pull-right">'+
                                '<div class="mui-pull-left jifen">'+
                                '<img src="/static/images/jifen2.png"/>'+
                                '<p>'+v.integral+'分</p>'+
                                '</div>'+
                                '<div class="mui-pull-left imgBox">'+
                                '<span>'+data.my+'</span>'+
                                '</div>'+
                                '</div>'+
                                '</li>';
						});

                        $str+="</ul>";
                        $("#scroller2").append($str);
                    });
                })
            },100);
        }else{
            mui.alert("发生未知错误，请稍后再试")
        }
    });

});

